<?php $this->headLink()->appendStylesheet('../WSB/3rdparty/jquery/css/smoothness/jquery-ui-1.7.2.custom.css') ?>
<?php $this->headScript()->appendFile('../WSB/3rdparty/jquery-1.3.2.min.js') ?>
<?php $this->headScript()->appendFile('../WSB/3rdparty/jquery/js/jquery-ui-1.7.2.custom.min.js') ?>

<h1><?php echo $this->translate('index.title') ?></h1>

<form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post" style="float:right">
    <?php echo $this->formText('filter', $this->filter) ?>
    <?php echo $this->formSubmit('submit', 'Filter') ?>
    <?php if(!empty($this->filter)): ?>
        <?php echo $this->formSubmit('reset', 'Reset') ?>
    <?php endif; ?>
</form>

<p><a class="add-link" href="<?php echo $this->url(array('action' => 'add')) ?>"><?php echo $this->translate('index.add') ?></a></p>

<table class="model2" border="0" cellspacing="0" cellpadding="0" style="clear:both">
    <tr>
    <?php foreach($this->columns AS $column): ?>
        <?php if($this->sortField == $column): ?>
            <?php $dir = ($this->sortDirection == 'asc') ? 'desc' : 'asc' ?>
        <?php else: ?>
            <?php $dir = 'asc'; ?>
        <?php endif; ?>
        <th><a href="<?php echo $this->url(array('sort' => $column, 'dir' => $dir)) ?>"><?php echo $this->translate($column) ?></a></th>
    <?php endforeach; ?>
        <th width="1%"></th>
    </tr>
<?php foreach($this->collection AS $m): ?>
    <tr>
        <?php foreach($this->columns AS $column): ?>
            <td><?php echo $m->$column ?></td>
        <?php endforeach; ?>
        <td nowrap="nowrap">
            <!-- Editieren -->
            <a href="<?php echo $this->url(array('action' => 'edit', 'id' => $m->id)) ?>"><?php echo $this->translate('index.edit') ?></a>

            <!-- Aktivieren/Deaktivieren -->
            <?php if(isset($m->hidden)): ?>
                <a rel="<?php echo $m->id ?>" class="enable" style="<?php echo empty($m->hidden) ? 'display:none' : 'display:inline' ?>" href="<?php echo $this->url(array('action' => 'enable', 'id' => $m->id)) ?>"><?php echo $this->translate('index.enable') ?></a>
                <a rel="<?php echo $m->id ?>" class="disable" style="<?php echo empty($m->hidden) ? 'display:inline' : 'display:none' ?>" href="<?php echo $this->url(array('action' => 'disable', 'id' => $m->id)) ?>"><?php echo $this->translate('index.disable') ?></a>
            <?php endif; ?>

            <!-- Löschen -->
            <a rel="<?php echo $m->id ?>" class="delete" href="<?php echo $this->url(array('action' => 'delete', 'id' => $m->id)) ?>"><?php echo $this->translate('index.delete') ?></a>

        </td>
    </tr>
<?php endforeach; ?>
</table>

<?php echo $this->paginationControl($this->paginator, 'Sliding', 'model/pagination_control.phtml'); ?>

<div id="dialog"></div>

<style type="text/css">

    table.model2 {
        border-collapse: collapse;
        width: 100%;
        border: 1px solid #ccc;
    }
    table.model2 th {
        padding: 4px;
        /*border-top: 1px solid #ccc;*/
        text-align: left;
    }
    table.model2 td {
        padding: 4px;
        border-top: 1px solid #ccc;
    }

</style>

<script type="text/javascript">

    function deleteConfirmationEventHandler()
    {
        var url = $(this).attr('href');
        var id = $(this).attr('rel');
        $('#dialog').dialog({
            autoOpen: true,
            title: "<?php echo $this->translate('delete.dialog.title') ?>",
            buttons: {
                "<?php echo $this->translate('delete.dialog.yesButton') ?>": function() {
                    $(this).dialog("close");
                    window.location.href = url;
                },
                "<?php echo $this->translate('delete.dialog.noButton') ?>": function() {
                    $(this).dialog("close");
                }
            },
            close: function() {
                $(this).dialog("destroy");
            }
        });
        var question = '<?php echo $this->translate('delete.dialog.text') ?>';
        question = question.replace("%ID%", id);
        $('div.ui-dialog-content').html('<p>' + question + '</p>');
        return false;
    }

    function toggleHiddenEventHandler()
    {
        var url = '<?php echo $this->url(array('action' => 'value1', 'id' => 'value2', 'format' => 'json')) ?>';
        var action = $(this).attr('class');
        var id = $(this).attr('rel');
        url = url.replace("value1", action);
        url = url.replace("value2", id);
        $.ajax({
            type: "GET",
            url: url,
            success: function() {
                $('a.enable[rel=' + id + ']').toggle();
                $('a.disable[rel=' + id + ']').toggle();
            }
        });
        return false;
    }

    $(document).ready(function() {
        $('a.enable').click(toggleHiddenEventHandler);
        $('a.disable').click(toggleHiddenEventHandler);
        $('a.delete').click(deleteConfirmationEventHandler);
    });

</script>
